package com.moore.controller;

import com.moore.bean.Contract;
import com.moore.dto.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.moore.service.ContractService;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    ContractService contractService;

    @GetMapping("/getContractInfo")
    @ResponseBody
    public ResponseData getContractInfo(String account) {
        return contractService.getContractInfo(account);
    }

    @PostMapping("/signContract")
    @ResponseBody
    public ResponseData signContract(@RequestBody Contract contract){
        return contractService.signContract(contract);
    }

    @PostMapping("/getAllContract")
    @ResponseBody
    public ResponseData getAllContract(@RequestBody Contract contract, HttpServletRequest request) {
        return contractService.getContractList(contract.getStartDate(), contract.getEndDate(), contract.getName(), contract.getStatus(), contract.getCurr(), contract.getSize(), request);
    }

    @PostMapping("/termination")
    @ResponseBody
    public ResponseData terminationContract(@RequestBody Contract contract){
        return contractService.terminationContract((int)contract.getId(), contract.getName(), contract.getMsg());
    }
}
